﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace SanJ.FreeCare.Locations
{
    public interface ILocationRepository : IRepository<Location, Guid>
    {
        Task<long> GetCountAsync(string filter, CancellationToken cancellationToken = default);

        Task<Location> GetByIdAsync(Guid id, bool isAsNoTracking = true);

       Task<Location> GetByCodeAsync(string code, bool isAsNoTracking = true);

        /// <summary>
        /// 通过id  获取location的code
        /// </summary>
        Task<string> GetCodeByIdAsync(Guid id);
        /// <summary>
        /// 获取parentId相同的机构
        /// </summary>
        /// <param name="parentId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<List<Location>> GetChildrenAsync(Guid? parentId, CancellationToken cancellationToken = default);

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="code">code</param>
        /// <param name="isAsNoTracking"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<List<Location>> GetListAsync(string code, bool isAsNoTracking = true, CancellationToken cancellationToken = default);

        /// <summary>
        /// 获取以code为开头的所有子级机构
        /// </summary>
        /// <param name="code">机构代码</param>
        /// <param name="parentId">机构父id</param>
        /// <param name="isAsNoTracking"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<List<Location>> GetAllChildrenWithParentCodeAsync(string code, Guid? parentId, bool isAsNoTracking = true, CancellationToken cancellationToken = default);

        /// <summary>
        /// 获取PhysicalType为room的位置
        /// </summary>
        Task<List<Location>> GetEmergencyLocationByPhysicalTypeAsync(string locationCode,string physicalType);

        /// <summary>
        /// 获取Type为room的位置
        /// </summary>
        Task<List<Location>> GetEmergencyLocationByTypeAsync(string locationCode, string type);

        /// <summary>
        /// 获取可用于分诊的全部位置
        /// </summary>
        Task<List<Location>> GetEmergencyCanTriageLocationAsync(string parentLocationCode);

        Task<int> GetActiveLocationCountAsync(string locCode, string locType, string locPhysicalType);

        /// <summary>
        /// 获取空床列表
        /// </summary>
        /// <param name="code">急诊code</param>
        Task<List<Location>> GetEmptyListAsync(string code, bool isAsNoTracking = true, CancellationToken cancellationToken = default);

        /// <summary>
        /// 获取所有院区位置
        /// </summary>
        /// <returns></returns>
        Task<List<Location>> GetAllHospitalLocListAsync();
        Task<List<Location>> GetPagedListAsync(string filter, string sorting, int maxResultCount, int skipCount);
    }
}
